package org.lojzes.lojzesframework.factory;
import java.lang.reflect.Proxy;

import org.lojzes.lojzesframework.handler.PreDaoHandler;
import org.springframework.beans.factory.FactoryBean;

public class PreDaoBeanFactory<T> implements FactoryBean<T> {
	private Class<T> classInterface;
	private PreDaoHandler handler;

	@SuppressWarnings("unchecked")
	public T getObject() throws Exception {
		return (T) Proxy.newProxyInstance(classInterface.getClassLoader(), new Class[] { classInterface }, handler);
	}

	public Class<?> getObjectType() {
		return classInterface;
	}

	public boolean isSingleton() {
		return true;
	}

	public void setClassInterface(Class<T> classInterface) {
		this.classInterface = classInterface;
	}

	public void setHandler(PreDaoHandler handler) {
		this.handler = handler;
	}
}
